package com.baizhi.service.impl;

import com.baizhi.dao.BannerDao;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/19.
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerDao bannerDao;

    @Override
    public void insertBanner(Banner banner) {
        bannerDao.insertBanner(banner);
    }

    @Override
    public void deleteBanner(int bannerId) {
        bannerDao.deleteBanner(bannerId);
    }

    @Override
    public void updateBanner(Banner banner) {
        bannerDao.updateBanner(banner);
    }

    @Override
    public Map selectBanner(int page, int rows) {
        int start = (page-1)*rows;
        int pageSize = rows;

        int countBanner = bannerDao.countBanner();
        List<Banner> bannerList = bannerDao.selectBanner(start, pageSize);
        Map map = new HashMap();
        map.put("total",countBanner);
        map.put("rows",bannerList);

        return map;
    }

    @Override
    public List<Banner> selectBannnerAll() {
        return bannerDao.selectBannnerAll();
    }
}
